I'm making a discord bot from a tutorial on yt. I'm a beginner in JS programming.
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Bot is online!');
});
client.login('My token');
and when i write in cmd "node ." i got this error
Error: Cannot find module 'C:\Users\48795\Desktop\DiscordBot\main.js'. Please verify that the package.json has a valid "main" entry
←[90m at tryPackage (internal/modules/cjs/loader.js:320:19)←[39m
←[90m at Function.Module._findPath (internal/modules/cjs/loader.js:533:18)←[39m
←[90m at resolveMainPath (internal/modules/run_main.js:16:25)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:70:24)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
path: ←[32m'C:\Users\48795\Desktop\DiscordBot\package.json'←[39m,
requestPath: ←[32m'C:\Users\48795\Desktop\DiscordBot'←[39m
}
How do i fix this error?
In your package.json, you need to put in the main field, the name of your script. In your case whatever you named your file.
The error tells me at least that your index/main file is different in your package.json than it really is. What is your main file called?
You should try renaming it to main.js OR just rename the main field in your package.json file.
In your package.json you need to make sure your "main" field points to your main.js file. Its probably looking for index.js.